#!/usr/bin/bash

# 0. 切换到脚本所在目录
script_dir=$(cd $(dirname $0);pwd)
cd $script_dir

# 1. 配置构建环境
source build/envsetup.sh

# 2. 配置 lunch 目标
lunch rk3568_s-userdebug


# 3. 使用升级工具 更新固件

# 升级 update.img 固件
# ./RKTools/linux/Linux_Upgrade_Tool/Linux_Upgrade_Tool_v1.65/upgrade_tool UF rockdev/Image-rk3568_s/update.img

# 测试设备
./RKTools/linux/Linux_Upgrade_Tool/Linux_Upgrade_Tool_v1.65/upgrade_tool TD

# 升级 loader
./RKTools/linux/Linux_Upgrade_Tool/Linux_Upgrade_Tool_v1.65/upgrade_tool UL rockdev/Image-rk3568_s/MiniLoaderAll.bin -noreset

# 下载分区表
./RKTools/linux/Linux_Upgrade_Tool/Linux_Upgrade_Tool_v1.65/upgrade_tool DI -p rockdev/Image-rk3568_s/parameter.txt

# 烧写分区镜像
# ./RKTools/linux/Linux_Upgrade_Tool/Linux_Upgrade_Tool_v1.65/upgrade_tool DI -uboot         rockdev/Image-rk3568_s/uboot.img
./RKTools/linux/Linux_Upgrade_Tool/Linux_Upgrade_Tool_v1.65/upgrade_tool DI -uboot         uboot.img
./RKTools/linux/Linux_Upgrade_Tool/Linux_Upgrade_Tool_v1.65/upgrade_tool DI -misc          rockdev/Image-rk3568_s/misc.img
./RKTools/linux/Linux_Upgrade_Tool/Linux_Upgrade_Tool_v1.65/upgrade_tool DI -dtbo          rockdev/Image-rk3568_s/dtbo.img
./RKTools/linux/Linux_Upgrade_Tool/Linux_Upgrade_Tool_v1.65/upgrade_tool DI -vbmeta        rockdev/Image-rk3568_s/vbmeta.img
./RKTools/linux/Linux_Upgrade_Tool/Linux_Upgrade_Tool_v1.65/upgrade_tool DI -boot          rockdev/Image-rk3568_s/boot.img
./RKTools/linux/Linux_Upgrade_Tool/Linux_Upgrade_Tool_v1.65/upgrade_tool DI -recovery      rockdev/Image-rk3568_s/recovery.img
./RKTools/linux/Linux_Upgrade_Tool/Linux_Upgrade_Tool_v1.65/upgrade_tool DI -baseparameter rockdev/Image-rk3568_s/baseparameter.img
./RKTools/linux/Linux_Upgrade_Tool/Linux_Upgrade_Tool_v1.65/upgrade_tool DI -super         rockdev/Image-rk3568_s/super.img


# 复位
./RKTools/linux/Linux_Upgrade_Tool/Linux_Upgrade_Tool_v1.65/upgrade_tool RD

# 烧写分区镜像
# ./RKTools/linux/Linux_Upgrade_Tool/Linux_Upgrade_Tool_v1.65/upgrade_tool DI \
#     -s rockdev/Image-rk3568_s/system.img -b rockdev/Image-rk3568_s/boot.img \
#     -u rockdev/Image-rk3568_s/uboot.img \


# 命令行模式
# CD 命令:选择设备
# SD 命令：切换设备
# UF 命令：升级 update.img 固件
# UL 命令：升级 loader
# DI 命令：烧写分区镜像 
    # -p|-b|-k|-s|-r|-m|-u|-t|-re 烧写指定分区镜像
    # -s(system 分区)
    # -k(kernel 分区)
    # -b(boot 分区)
    # -r(recovery 分区) 
    # -m(misc 分区) 
    # -u(uboot 分区) 
    # -t(trust 分区)
    # -re(resource 分区)
    # -p 设备已烧录过 parameter 情况下,烧写多个分区镜像命令：

# DB 命令：下载 Boot 
# EF 命令：擦除 Flash
# PL 命令：读取分区表